package com.sqtracker.recommender.controller;

import com.sqtracker.recommender.service.TorrentMetadataSyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/admin/sync")
public class TorrentSyncController {

    private final TorrentMetadataSyncService syncService;

    @Autowired
    public TorrentSyncController(TorrentMetadataSyncService syncService) {
        this.syncService = syncService;
    }

    @PostMapping("/torrents")
    public ResponseEntity<Map<String, Object>> syncTorrents() {
        Map<String, Object> result = syncService.forceSyncNow();
        return ResponseEntity.ok(result);
    }

    @GetMapping("/status")
    public ResponseEntity<Map<String, String>> getSyncStatus() {
        // 实际项目中可以添加监控同步状态的逻辑
        Map<String, String> status = Map.of(
                "lastSyncTime", "查询数据库获取最新同步时间",
                "status", "active"
        );
        return ResponseEntity.ok(status);
    }
}